<template>
  <div class="bg">
    <el-card class="wrap">
      <div slot="header" class="clearfix">
        <span>后台管理</span>
      </div>
      <el-form label-width="80px" @submit.native.prevent="login">
        <el-form-item label="账号">
          <el-input
            v-model="model.username"
            placeholder="请输入管理员账号"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            v-model="model.password"
            placeholder="请输入管理员密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" native-type="submit">登陆</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      model: {}
    }
  },
  methods: {
    async login () {
      if (!this.model.username || !this.model.password) {
        return this.$message({
          message: '请填写数据',
          type: 'error'
        })
      }
      const res = await this.$http.post('login', this.model)
      localStorage.token = res.data.token
      console.log(localStorage.token)
      this.$router.push('/')
      this.$message({
        message: '登陆成功',
        type: 'success'
      })
    }
  }
}
</script>

<style scoped>
.bg {
  position: absolute;
  background: blue linear-gradient(rgba(147, 212, 236, 0.842), blue);
  height: 100vh;
  width: 100vw;
}
.wrap {
  width: 40vw;
  margin: 10rem auto;
}
</style>
